package com.glela.order.dao.impl;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.glela.goods.model.GoodsCommission;
import com.glela.goods.model.LimitTimeSaleGoodsCommission;
import com.glela.goods.model.ShareGoods;
import com.glela.goods.model.TalentSerialGood;
import com.glela.goods.model.vo.InventoryVo;
import com.glela.order.dao.OrderDao;
import com.glela.order.mapper.CommisionMapper;
import com.glela.order.mapper.OrderDetailMapper;
import com.glela.order.mapper.OrderInfoMapper;
import com.glela.order.mapper.OrderObjectMapper;
import com.glela.order.mapper.OrderSettlementMapper;
import com.glela.order.mapper.OrderStatusMapper;
import com.glela.order.mapper.PayTypeConfigMapper;
import com.glela.order.model.Commision;
import com.glela.order.model.OrderDetail;
import com.glela.order.model.OrderInfo;
import com.glela.order.model.OrderObject;
import com.glela.order.model.OrderSettlement;
import com.glela.order.model.OrderStatus;
import com.glela.order.model.PayTypeConfig;
import com.glela.order.model.PayTypeList;
import com.glela.order.vo.OrderDetailVo;
import com.glela.order.vo.OrderInfoVo;
import com.glela.order.vo.OrderSettlementVo;
import com.glela.platform.model.response.ResponseUser;
import com.glela.platform.vo.GoodsSimpleVo;

/**
 * @author liujie
 * @2016年10月25日
 */
@Repository
public class OrderDaoImpl implements OrderDao {

	@Autowired
	private OrderDetailMapper orderDetailMapper;
	
	@Autowired
	private OrderInfoMapper orderInfoMapper;
	@Autowired
	private OrderObjectMapper orderObjectMapper;
	@Autowired
	private CommisionMapper commisionMapper;
	@Autowired
	private OrderSettlementMapper orderSettlementMapper;
	@Autowired
	private PayTypeConfigMapper payTypeConfigMapper;
	@Autowired
	private OrderStatusMapper orderStatusMapper;

	@Override
	public OrderDetail selectByUserGoodApplywelfareId(long userId, long goodId, int applywelfareId,int activityType) {
		return orderDetailMapper.selectByUserGoodApplywelfareId(userId, goodId, applywelfareId,activityType);
	}

	@Override
	public List<OrderObject> selectOpenOrder(Long buyUserId) {
		if (buyUserId==null||buyUserId<1) {
			return new LinkedList<>();
		}
		return orderObjectMapper.selectOpenOrder(buyUserId);
	}

	@Override
	public List<GoodsSimpleVo> selectGetOrderGoodsInfo(List<GoodsSimpleVo> goods) {
		return orderObjectMapper.selectGetOrderGoodsInfo(goods);
	}

	@Override
	public List<GoodsSimpleVo> selectGetOrderGoodsInfo(Collection<Long> inventoryIds) {
		return orderObjectMapper.selectGetOrderGoodsInfoByInventoryIds(inventoryIds);
	}

	@Override
	public int batchSubInventoryNumById(List<OrderDetail> orderDetailList) {
		// TODO Auto-generated method stub
		return orderDetailMapper.batchSubInventoryNumById(orderDetailList);
	}

	@Override
	public List<InventoryVo> selectInventoryInId(Set<Long> inventoryIdSet) {
		return orderDetailMapper.selectInventoryInId(inventoryIdSet);
	}
	
	@Override
	public int insertSelective(OrderObject orderObject) {
		return orderObjectMapper.insertSelective(orderObject);
	}
	
	@Override
	public OrderObject selectOrderObjectByPrimaryKey(long id) {
		return orderObjectMapper.selectByPrimaryKey(id);
	}

	@Override
	public OrderObject selectOrderObjectByOrderSn(String orderSn) {
		// TODO Auto-generated method stub
		return orderObjectMapper.selectByOrderSn(orderSn);
	}

	@Override
	public int insertOrderObjectSelective(OrderObject record) {
		// TODO Auto-generated method stub
		return orderObjectMapper.insertSelective(record);
	}

	@Override
	public int batchInsertOrderInfo(List<OrderInfo> list) {
		// TODO Auto-generated method stub
		return orderInfoMapper.batchInsert(list);
	}

	@Override
	public int batchInsertOrderDetail(List<OrderDetail> list) {
		// TODO Auto-generated method stub
		return orderDetailMapper.batchInsert(list);
	}

	@Override
	public int insertOrderInfoSelective(OrderInfo orderInfo) {
		// TODO Auto-generated method stub
		return orderInfoMapper.insertSelective(orderInfo);
	}

	@Override
	public int subInventoryNumById(long inventoryId, int quantity) {
		// TODO Auto-generated method stub
		return orderDetailMapper.subInventoryNumById(inventoryId, quantity);
	}

	@Override
	public List<TalentSerialGood> selectTalentSerialGoodInId(
			List<GoodsSimpleVo> list) {
		// TODO Auto-generated method stub
		return orderDetailMapper.selectTalentSerialGoodInId(list);
	}

	@Override
	public List<ShareGoods> selectShareGoodsInId(List<GoodsSimpleVo> list) {
		// TODO Auto-generated method stub
		return orderDetailMapper.selectShareGoodsInId(list);
	}

	@Override
	public List<OrderDetail> selectOrderDetilByOrderObjectId(Long orderObjectId) {
		// TODO Auto-generated method stub
		return orderDetailMapper.selectOrderDetilByOrderObjectId(orderObjectId);
	}

	@Override
	public List<GoodsCommission> selectGoodsCommissionListInGoodId(List<OrderDetail> inOrderDetailList) {
		// TODO Auto-generated method stub
		return orderDetailMapper.selectGoodsCommissionListInGoodId(inOrderDetailList);
	}
	@Override
	public List<LimitTimeSaleGoodsCommission> selectLimitTimeSaleGoodsCommissionListInGoodId(List<OrderDetail> inOrderDetailList) {
		// TODO Auto-generated method stub
		return orderDetailMapper.selectLimitTimeSaleGoodsCommissionListInGoodId(inOrderDetailList);
	}

	@Override
	public List<ResponseUser> selectTalentIdAndUserReRoleInId(List<OrderDetail> orderDetailList, ResponseUser user) {
		// TODO Auto-generated method stub
		return orderDetailMapper.selectTalentIdAndUserReRoleInId(orderDetailList, user);
	}

	@Override
	public List<ResponseUser> selectUserRoleInPersonId(List<String> personIdlist) {
		// TODO Auto-generated method stub
		return orderDetailMapper.selectUserRoleInPersonId(personIdlist);
	}

	@Override
	public int batchInsertCommision(List<Commision> list) {
		// TODO Auto-generated method stub
		return commisionMapper.batchInsert(list);
	}

	@Override
	public int batchInsertOrderSettlement(List<OrderSettlement> list) {
		// TODO Auto-generated method stub
		return orderSettlementMapper.batchInsert(list);
	}

	@Override
	public int updateOrderObjectByPrimaryKeySelective(OrderObject record) {
		// TODO Auto-generated method stub
		return orderObjectMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int batchUpdateCommisionFeeAndPointFeeById(List<OrderInfo> list) {
		// TODO Auto-generated method stub
		return orderInfoMapper.batchUpdateCommisionFeeAndPointFeeById(list);
	}

	@Override
	public List<OrderObject> selectOrderObjectForCommision() {
		// TODO Auto-generated method stub
		return orderObjectMapper.selectOrderObjectForCommision();
	}

	@Override
	public List<Commision> selectByOrderObjectIdForCommision(long orderOBJid) {
		// TODO Auto-generated method stub
		return commisionMapper.selectByOrderObjectIdForCommision(orderOBJid);
	}

	@Override
	public List<Commision> selectInOrderObjectIdForCommision(List<OrderObject> orderObjectList) {
		// TODO Auto-generated method stub
		return commisionMapper.selectInOrderObjectIdForCommision(orderObjectList);
	}

	@Override
	public List<OrderInfo> selectOrderInfoInOOIdForCommision(List<OrderObject> orderObjectList) {
		// TODO Auto-generated method stub
		return orderInfoMapper.selectOrderInfoInOOIdForCommision(orderObjectList);
	}

	@Override
	public int updateCommisionResultInId(List<Commision> commisionList,String resultTime) {
		// TODO Auto-generated method stub
		return commisionMapper.updateResultInId(commisionList,resultTime);
	}

	@Override
	public int updateOrderDetailStatusInOrderObjectId(List<OrderObject> orderObjectList) {
		// TODO Auto-generated method stub
		return orderDetailMapper.updateStatusInOrderObjectId(orderObjectList);
	}

	@Override
	public int updateOrderInfoStatusInOrderObjectId(List<OrderObject> orderObjectList) {
		// TODO Auto-generated method stub
		return orderInfoMapper.updateStatusInOrderObjectId(orderObjectList);
	}

	@Override
	public int updateOrderObjectStatusInId(List<OrderObject> orderObjectList) {
		// TODO Auto-generated method stub
		return orderObjectMapper.updateStatusInId(orderObjectList);
	}

	@Override
	public int updateOrderObjectPay(long id, long bankIn, long procedureFee, int payType, long paymentFee, String payId, String payTime) {
		return orderObjectMapper.updateOrderObjectPay(id, bankIn, procedureFee, payType, paymentFee, payId, payTime);
	}

	@Override
	public int updateOrderInfoPayByOrderObjectId(long orderObjectId, int bankIn, int procedureFee, int payType, int paymentFee, String payId, String payTime) {
		return orderInfoMapper.updateOrderInfoPayByOrderObjectId(orderObjectId, bankIn, procedureFee, payType, paymentFee, payId, payTime);
	}

	@Override
	public OrderInfo selectOrderInfoEntityByOrderSn(String orderSn) {
		// TODO Auto-generated method stub
		return orderInfoMapper.selectOrderInfoEntityByOrderSn(orderSn);
	}

	@Override
	public List<OrderInfoVo> selectOrderInfoVoByStatusOrderObjectSn(String orderSn, Integer status) {
		return orderInfoMapper.selectOrderInfoVoByStatusOrderObjectSn(orderSn, status);
	}

	@Override
	public List<OrderDetailVo> selectOrderDetailByStatusOrderObjectSn(String orderSn, Integer status) {
		return orderDetailMapper.selectOrderDetailByStatusOrderObjectSn(orderSn, status);
	}

	@Override
	public int updateOrderDetailPayByOrderObjectId(long orderObjectId) {
		// TODO Auto-generated method stub
		return orderDetailMapper.updateOrderDetailPayByOrderObjectId(orderObjectId);
	}

	@Override
	public List<PayTypeConfig> selectPayTypeConfigByStatus(Integer status) {
		return payTypeConfigMapper.selectByStatus(status);
	}

	@Override
	public List<PayTypeList> selectPayTypeList(PayTypeList queryPayTypeList) {
		return payTypeConfigMapper.selectPayTypeList(queryPayTypeList);
	}

	@Override
	public int updateSettlementStatusByID(Long ID, int status,String settlementNo,String companyAccount,String managerAccount,int selfSupport) {
		// TODO Auto-generated method stub
		return orderSettlementMapper.updateStatusByID(ID, status,settlementNo,companyAccount,managerAccount,selfSupport);
	}
	
	
	@Override
	public int updateStatusBySettlementId(Long settlementId, int status,String settlementNo,String companyAccount,String managerAccount) {
		// TODO Auto-generated method stub
		return orderSettlementMapper.updateStatusBySettlementId(settlementId, status,settlementNo,companyAccount,managerAccount);
	}
	
	
	@Override
	public int updateSettlementStatusByOrderSn(String orderSn, int status,String settlementNo) {
		// TODO Auto-generated method stub
		return orderSettlementMapper.updateStatusByOrderSn0(orderSn, status,settlementNo);
	}

	@Override
	public List<OrderSettlementVo> selectByOrderSnForSettlement(String orderSn) {
		// TODO Auto-generated method stub
		return orderSettlementMapper.selectByOrderSnForSettlement(orderSn);
	}

	@Override
	public List<OrderSettlementVo> selectByOrderSnForFreightSettlement(
			String orderSn) {
		// TODO Auto-generated method stub
		return orderSettlementMapper.selectByOrderSnForFreightSettlement(orderSn);
	}
	
	@Override
	public int updateOrderObjectPayUrlById(long id, String payUrl) {
		// TODO Auto-generated method stub
		return orderObjectMapper.updateOrderObjectPayUrlById(id, payUrl);
	}

	@Override
	public int updateOrderObjectFreightNo(Long orderObjectId, String refundFeeNo) {
		// TODO Auto-generated method stub
		return orderObjectMapper.updateOrderObjectFreightNo(orderObjectId, refundFeeNo);
	}

	@Override
	public List<OrderSettlementVo> selectByOrderSnForSettlementDetail(
			String orderSn) {
		// TODO Auto-generated method stub
		return orderSettlementMapper.selectByOrderSnForSettlementDetail(orderSn);
	}

	@Override
	public int selectDetailGoodsType(Long orderObjectId) {
		// TODO Auto-generated method stub
		return orderDetailMapper.selectDetailGoodsType(orderObjectId);
	}

	@Override
	public String selectSettlementAccount(Long orderObjectId) {
		// TODO Auto-generated method stub
		return orderSettlementMapper.selectSettlementAccount(orderObjectId);
	}

	@Override
	public int updateHandlestatusByOrderSn(String orderSn) {
		// TODO Auto-generated method stub
		return orderObjectMapper.updateHandlestatusByOrderSn(orderSn);
	}

	@Override
	public List<OrderStatus> selectForStatusUserOrderObjectSn(String orderObjectSn) {
		// TODO Auto-generated method stub
		return orderStatusMapper.selectForStatusUserOrderObjectSn(orderObjectSn);
	}

	@Override
	public int updateOrderDetailStatusByOrderInfoId(long orderInfoId,int nextStatus, int limitStatus) {
		// TODO Auto-generated method stub
		return orderStatusMapper.updateOrderDetailStatusByOrderInfoId(orderInfoId,nextStatus,limitStatus);
	}

	@Override
	public int updateOrderInfoStatusById(long orderInfoId, int nextStatus, int limitStatus) {
		// TODO Auto-generated method stub
		return orderStatusMapper.updateOrderInfoStatusById(orderInfoId,nextStatus,limitStatus);
	}

	@Override
	public int updateOrderInfoCompanyAndJobNoById(long orderInfoId, Integer companyId, String jobNo) {
		// TODO Auto-generated method stub
		return orderInfoMapper.updateOrderInfoCompanyAndJobNoById(orderInfoId,companyId,jobNo);
	}
	@Override
	public int updateOrderObjectStatusById(long orderObjectId,int nextStatus, int limitStatus) {
		// TODO Auto-generated method stub
		return orderStatusMapper.updateOrderObjectStatusById(orderObjectId,nextStatus,limitStatus);
	}

	@Override
	public String selectOrderObjectSnByOrderInfoSn(String orderInfoSn) {
		// TODO Auto-generated method stub
		return orderStatusMapper.selectOrderObjectSnByOrderInfoSn(orderInfoSn);
	}

	@Override
	public int updateOrderDetailStatusById(long orderDetailId,int nextStatus, int limitStatus) {
		// TODO Auto-generated method stub
		return orderStatusMapper.updateOrderDetailStatusById(orderDetailId, nextStatus, limitStatus);
	}

	@Override
	public String selectOrderObjectSnById(Long orderObjectId) {
		// TODO Auto-generated method stub
		return orderStatusMapper.selectOrderObjectSnById(orderObjectId);
	}

	@Override
	public int updateOrderStatusSuccess(String orderObjectSn) {
		// TODO Auto-generated method stub
		return orderStatusMapper.updateOrderStatusSuccess(orderObjectSn);
	}

	@Override
	public int updateConfirmTime(long orderInfoId, String confirmTime) {
		// TODO Auto-generated method stub
		return orderInfoMapper.updateConfirmTime(orderInfoId,confirmTime);
	}

	@Override
	public int selectCountByStatus(Long userId, int status) {
		return orderObjectMapper.selectCountByStatus(userId, status);
	}
	
}
